	package worktest;
	 
	import java.util.HashMap;
	 
	/**
	 * hashMap的碰撞原理
	 * @author Administrator
	 *
	 */
	public class TestMap {
		public static void main(String[] args) {
			HashMap<Player, Team> map = new HashMap<Player, Team>();
			Player iverson = new Player();
			iverson.setHeight(183);
			iverson.setId(3);
			iverson.setName("iverson");
			
			Player kobe = new Player();
			kobe.setHeight(196);
			kobe.setId(8);
			kobe.setName("kobe");
			
			
			Team sixers = new Team();
			sixers.setId(1);
			sixers.setName("sixers");
			
			Team lakers = new Team();
			lakers.setId(2);
			lakers.setName("lakers");
			
			map.put(iverson, sixers);
			map.put(kobe, lakers);
			
			System.out.println("--" + map.get(iverson).getName());
			System.out.println("--" + map.get(kobe).getName());
			
			System.out.println(iverson.equals(kobe));
		}
	}
	 
	class Team {
		private int id = 0;
		private String name = "";
	 
		public int getId() {
			return id;
		}
	 
		public void setId(int id) {
			this.id = id;
		}
	 
		public String getName() {
			return name;
		}
	 
		public void setName(String name) {
			this.name = name;
		}
	 
		@Override
		public int hashCode() {
			System.out.println("team 's hashCode() invoked");
			return id;
		}
	 
		@Override
		public boolean equals(Object obj) {
			System.out.println("team 's equals invokes");
			return super.equals(obj);
		}
	}
	 
	class Player {
		private int id = 0;
		private String name = "";
		private int height = 0;
	 
		@Override
		public int hashCode() {
			System.out.println("player name:" + name + ",hashCode() invoked,"+ "hashcode:" + "NBA".hashCode() +"---"+ this.height);
			return "NBA".hashCode();
		}
	 
		public int getId() {
			return id;
		}
	 
		public void setId(int id) {
			this.id = id;
		}
	 
		public String getName() {
			return name;
		}
	 
		public void setName(String name) {
			this.name = name;
		}
	 
		public int getHeight() {
			return height;
		}
	 
		public void setHeight(int height) {
			this.height = height;
		}
	 
		@Override
		public String toString() {
			return "id:" + id + "; Name:" + this.name + "; height:" + this.height;
		}
	 
		@Override
		public boolean equals(Object obj) {
			System.out.println("name:" + name + ", equals invokes");
			return super.equals(obj);
		}
	}
